import {
  Column,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { RrzArticleNodes } from '../entity/rrz_article_nodes.entity';

@Index('idx_node_id', ['nodeId'], {})
@Index('idx_is_head', ['isHead'], {})
@Index('idx_is_special', ['isSpecial'], {})
@Index('idx_is_recom', ['isRecom'], {})
@Index('idx_ifpub', ['ifpub'], {})
@Entity('rrz_articles', { schema: 'rrzcms' })
export class RrzArticles {
  @PrimaryGeneratedColumn({
    type: 'bigint',
    name: 'id',
    comment: '表id',
    unsigned: true,
  })
  id: string;

  @Column('mediumint', {
    name: 'node_id',
    comment: '类别ID',
    default: () => "'0'",
  })
  nodeId: number;

  @Column('varchar', { name: 'title', comment: '文章标题', length: 255 })
  title: string;

  @Column('varchar', {
    name: 'subtitle',
    nullable: true,
    comment: '副标题',
    length: 255,
  })
  subtitle: string | null;

  @Column('varchar', { name: 'img', comment: '文章配图', length: 255 })
  img: string;

  @Column('varchar', {
    name: 'tmpl_path',
    nullable: true,
    comment: '模板',
    length: 100,
  })
  tmplPath: string | null;

  @Column('longtext', { name: 'content', nullable: true, comment: '文章内容' })
  content: string | null;

  @Column('longtext', {
    name: 'wap_content',
    nullable: true,
    comment: '手机端内容',
  })
  wapContent: string | null;

  @Column('varchar', { name: 'author', comment: '文章作者', length: 100 })
  author: string;

  @Column('varchar', { name: 'author_email', comment: '作者邮箱', length: 60 })
  authorEmail: string;

  @Column('int', {
    name: 'uptime',
    nullable: true,
    comment: '更新时间',
    unsigned: true,
    default: () => "'0'",
  })
  uptime: number | null;

  @Column('int', {
    name: 'pubtime',
    nullable: true,
    comment: '文章发布时间',
    unsigned: true,
    default: () => "'0'",
  })
  pubtime: number | null;

  @Column('enum', {
    name: 'ifpub',
    comment: '发布',
    enum: ['true', 'false'],
    default: () => "'false'",
  })
  ifpub: 'true' | 'false';

  @Column('varchar', {
    name: 'seo_title',
    nullable: true,
    comment: 'SEO标题',
    length: 255,
  })
  seoTitle: string | null;

  @Column('mediumtext', {
    name: 'seo_description',
    nullable: true,
    comment: '分类描述',
  })
  seoDescription: string | null;

  @Column('varchar', {
    name: 'seo_keywords',
    nullable: true,
    comment: '搜索关键词',
    length: 200,
  })
  seoKeywords: string | null;

  @Column('int', {
    name: 'view_count',
    comment: '浏览量',
    unsigned: true,
    default: () => "'0'",
  })
  viewCount: number;

  @Column('int', {
    name: 'add_time',
    nullable: true,
    comment: '文章创建时间',
    unsigned: true,
  })
  addTime: number | null;

  @Column('tinyint', {
    name: 'is_head',
    nullable: true,
    comment: '头条（0=否，1=是）',
    unsigned: true,
    default: () => "'0'",
  })
  isHead: number | null;

  @Column('tinyint', {
    name: 'is_special',
    nullable: true,
    comment: '特荐（0=否，1=是）',
    unsigned: true,
    default: () => "'0'",
  })
  isSpecial: number | null;

  @Column('tinyint', {
    name: 'is_recom',
    nullable: true,
    comment: '推荐（0=否，1=是）',
    unsigned: true,
    default: () => "'0'",
  })
  isRecom: number | null;

  @Column('smallint', {
    name: 'sort',
    nullable: true,
    comment: '排序',
    unsigned: true,
    default: () => "'100'",
  })
  sort: number | null;

  @Column('varchar', { name: 'source', comment: '来源', length: 100 })
  source: string;

  @Column('varchar', { name: 'source_url', comment: '来源URL', length: 255 })
  sourceUrl: string;

  @Column('varchar', {
    name: 'url',
    comment: '音频来源',
    length: 255,
  })
  url: string;

  @Column('int', {
    name: 'duration',
    nullable: true,
    comment: '音频时长',
    unsigned: true,
  })
  duration: number | null;

  @ManyToOne(() => RrzArticleNodes, (rrzArticleNodes) => rrzArticleNodes)
  @JoinColumn({ name: 'node_id' })
  node: RrzArticleNodes;
}
